


$(document).ready(function() {
	formConfig();
	
	tmp();
});

 
 
 
 

/**
 * config hotel data form with the jquery.form plugin
 */
function formConfig() {
	
	var msgLabel = $('#msgLabel');
	
	var opt = {
		dataType: 	'json',
		type: 		'post',
		success: 	function(data) {
			
			if ( data.Result === 'OK' ) {
				msgLabel.removeClass().addClass('alert alert-success').html(data.msg);
				setTimeout(function() {msgLabel.removeClass().html('');}, 2000);
			}
			else {
				msgLabel.removeClass().addClass('alert alert-error') .html(data.msg);
				setTimeout(function() {msgLabel.removeClass().html('');}, 2000);
			}
			
			// set label that indicates the val was succefull saved
			//console.log('data returned: ' , data);
		},
		error: 		function() {
		}
	};
	
	$('#hotelSettingsForm').ajaxForm(opt);
	
	//var param = {var01: 'val01', var02: 'val02'};
	//var tmpData = getDataFromServer(param, '/tmp', false);
}









/**
 * retrieve data from server with 'POST' method
 * @param data to send to the server
 * @param method server method to make the call
 * @param async async or sync?
 * @returns
 */
function getDataFromServer(data, method, async) {
	
	var returnData = null;
	
	var opt = {
		url: 		window.ajaxUrl + method,
		async: 		async, // ... wait to retrieve the data from the server
		data: 		{ data: data },
		type: 		'POST',
		dataType: 	'json',
		success: 	function(serverData) {
			returnData = serverData;
		}
	};
	
	$.ajax(opt);
	
	return data;
}




function tmp() {
	
	$('#tmpButton').click(function() {
		var param = {var01: 'val01', var02: 'val02'};
		var tmpData = getDataFromServer(param, '/tmp', false);
		console.log(tmpData);
	});
	
}